<template>
	<view>
		<navbar title="工作统计"></navbar>
		<view class="fixed-box">
			<view class="date-box fa jcsb">
				<view class="fa">
					<image class="calendar-icon" src="../../static/calendar.png" mode=""></image>
					<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
						<view>{{date}}</view>
					</picker>
					<view style="margin: 0 10rpx;">-</view>
					<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange2">
						<view>{{date2}}</view>
					</picker>
					<image class="down-icon" src="../../static/down.png" mode=""></image>
				</view>
				<view>订单数量 {{count}}</view>
			</view>
			<view class="fixed-place"></view>
		</view>
		<view class="order-box" v-if="list.length > 0">
			<view class="order-list" v-for="(item, index) in list" :key="index">
				<view class="title fa jcsb">
					<view v-if="item.type == 1">取送订单</view>
					<view v-else>商城订单</view>
					<view>￥{{item.money}}</view>
				</view>
				<view class="sn">订单编号：{{item.ordersNo}}</view>
				<view class="time">{{item.createTime}}</view>
			</view>
		</view>
		<view class="nodata-box fa fdc" v-if="nodata">
			<image class="nodata-img" src="../../static/nodata.png" mode=""></image>
			<view class="prompt">暂无订单</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			const currentDate = this.getDate({
				format: true
			})
			return {
				page: 1,
				count: 0,
				list: [],
				nodata: 0,
				date: currentDate,
				date2: currentDate,
			};
		},
		computed: {
			startDate() {
				return this.getDate('start');
			},
			endDate() {
				return this.getDate('end');
			}
		},
		onLoad() {
			this.getList()
		},
		onReachBottom() {
			if(this.list.length < this.count) {
				this.page++
				this.getList()
			}
		},
		methods: {
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
	
				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			bindDateChange(e) {
				this.date = e.detail.value
				this.getList()
			},
			bindDateChange2(e) {
				this.date2 = e.detail.value
				this.getList()
			},
			// 获取订单列表
			getList() {
				this.nodata = 0
				this.api.hallListFunc({
					isReceive: 1,
					startTime: this.date,
					endTime: this.date2,
					pageNum: this.page
				}).then(res => {
					if(res.code == 200) {
						this.count = res.total
						this.list = this.page == 1 ? res.rows : this.list.concat(res.rows)
						this.nodata = this.list.length > 0 ? 0 : 1
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.date-box{
		position: fixed;
		z-index: 999;
		left: 0;
		right: 0;
		padding: 0 26rpx;
		height: 60rpx;
		font-size: 24rpx;
		background-color: var(--bodybg);
		.calendar-icon{
			margin-right: 10rpx;
			width: 30rpx;
			height: 30rpx;
		}
		.down-icon{
			margin-left: 6rpx;
			width: 20rpx;
			height: 20rpx;
		}
	}
	.fixed-place{
		height: 60rpx;
	}
	.order-box{
		margin: 26rpx 24rpx;
		padding: 0 26rpx;
		border-radius: 16rpx;
		background-color: #fff;
		.order-list{
			padding: 28rpx 0;
			border-bottom: 2rpx solid #F3F3F3;
			&:last-child{
				border-bottom: none;
			}
			.title{
				font-weight: bold;
				line-height: 32rpx;
			}
			.sn{
				margin-top: 8rpx;
				font-size: 26rpx;
				line-height: 30rpx;
			}
			.time{
				margin-top: 12rpx;
				font-size: 22rpx;
				color: #aaa;
				line-height: 26rpx;
			}
		}
	}
</style>
